package com.gxa.jd.controller;

import com.gxa.jd.pojo.Goods;
import com.gxa.jd.service.GoodsService;
import com.gxa.entity.PageResult;
import com.gxa.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/goods")
@Api(description = "商品接口文档")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/findAll")
    @ApiOperation(value = "查询所有商品", notes = "查询所有商品", httpMethod = "POST")
    public List<Goods> findAll() {
        return goodsService.findAll();
    }

    @PostMapping("/findPage")
    @ApiOperation(value = "分页查询", notes = "分页查询", httpMethod = "POST")
    public PageResult<Goods> findPage(int page, int size) {
        return goodsService.findPage(page, size);
    }

//    @PostMapping("/findList")
//    public List<Goods> findList(@RequestBody Map<String, Object> searchMap) {
//        return goodsService.findList(searchMap);
//    }

//    @PostMapping("/findPage")
//    public PageResult<Goods> findPage(@RequestBody Map<String, Object> searchMap, int page, int size) {
//        return goodsService.findPage(searchMap, page, size);
//    }


    @PostMapping("/add")
    @ApiOperation(value = "商品添加", notes = "商品添加", httpMethod = "POST")
    public Result add(@RequestBody Goods goods) {
        goodsService.add(goods);
        return new Result();
    }

    @PostMapping("/update")
    @ApiOperation(value = "商品编辑", notes = "商品编辑", httpMethod = "POST")
    public Result update(@RequestBody Goods goods) {
        goodsService.update(goods);
        return new Result();
    }

    @GetMapping("/delete")
    @ApiOperation(value = "商品删除", notes = "商品删除", httpMethod = "POST")
    public Result delete(Long id) {
        goodsService.delete(id);
        return new Result();
    }

}
